﻿using Gp.Scripts.Equip;
using Gp.Scripts.Core;
using QFramework;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Gp.Scripts.GUI {
    public class EquipSlotItem : MonoBehaviour {
        public Image icon;

        public Image selectionMark;

        public TMP_Text nameText;

        public TMP_Text descriptionText;

        public Button button;

        public WeaponEntity Entity { get; private set; }


        private UnitEquipSlotUIController _parent;

        public int Index { get; private set; }

        public void Init(UnitEquipSlotUIController controller, int index) {
            Index = index;
            _parent = controller;
            if (!button) {
                button = this.GetOrAddComponent<Button>();
            }

            button.onClick.AddListener(() => {
                if (Global.Get<BattleSystem>().IsBlocked) return;
                _parent.OnSlotButtonDown(this, Entity.ComEquip.Unit);
            });
        }

        public void UpdateSlot(WeaponEntity entity) {
            // var config = entity.Config;
            // Entity = entity;
            // if (config == null) return;
            //
            //
            // // this.icon.sprite = data.;
            // this.nameText.text = config.Name;
        }


        public void MarkSelect() {
            selectionMark.Show();
        }

        public void UnMarkSelect() {
            selectionMark.Hide();
        }
    }
}